home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 956 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: vandevod@cs.rpi.edu (David Vandevoorde)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Syntax for template instantiation and specialization
  5. Date: 03 Apr 1996 09:23:04 PST
  6. Organization: RPI Computer Science
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <xsok9zx1f0b.fsf@avs.cs.rpi.edu>
  9. References: <4jr0ur$bdh@wn1.sci.kun.nl>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 03 Apr 1996 10:52:36 -0500
  12. In-Reply-To: Marian Hellema's message of 02 Apr 96 13:34:59 GMT
  13. X-Newsreader: Gnus v5.1
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMWKz+Uy4NqrwXLNJAQGWdAH+K5LOm3kMswWOxfv9ok5wudyw+7m53Adb
  16.     6neHlqQ+RwthR6O5q/QR28KOfLhY87g7Ze+/3sCekM0lkPSN589OkQ==
  17.     =DZZW
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. >>>>> "MH" == Marian Hellema <marian@atcmp.nl> writes:
  21. MH> What is the correct syntax for template instantiation and
  22. MH> specialization?
  23.  
  24. MH> From my copy of the DWP April 95 I gather:
  25.  
  26. This has changed somewhat since then...
  27.  
  28. MH> template<class T>
  29. MH> T max(T a, T b) { return a>b?a:b; }
  30.  
  31. MH> template int max<int>(int, int);    //instantiation
  32. MH> /* OR: */ 
  33. MH> template int max<>(int, int);        //instantiation
  34.  
  35. (or you can leave out the `<>', I think).
  36.  
  37. MH> const char* max<const char*>max(const char* a, const char* b)
  38. MH> {  /* specialization */ }
  39.  
  40. Should now be:
  41.  
  42.     template<>    // <- note this!
  43.     char const*
  44.     max<char const*>(char const*, char const*) // ...
  45.  
  46. MH> const char* max<>(const char* a, const char* b)
  47. MH> {  /* specialization */ }
  48.  
  49. Same thing...
  50.  
  51.     template<>    // <- note this!
  52.     char const*
  53.     max(char const*, char const*) // ...
  54.  
  55. should be OK. I believe `max<>' would be fine too.
  56. (I'm deducing this from _examples_ in a not-yet-WP rework of the 
  57. templates-chapter; I could very well be very wrong).
  58.  
  59. [...]
  60. MH> 2. Is the following still legal:
  61. MH>    int max(int, int);    //instantiation??
  62.  
  63. It is still legal and I believe this is what would be called a
  64. ``guiding function declaration''. Without the guiding declaration
  65.  
  66.     max('a', 100);
  67.  
  68. would not find a match (because conversions are not considered when
  69. matching template arguments); _with_ the guiding declaration, the
  70. regular overloading rules (possibly involving implicit conversions)
  71. apply.
  72.  
  73.     Daveed
  74. ---
  75. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  76.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  77.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  78.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  79.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  80. ]
  81.